/**
 * 
 */


var xmlhttp;

function Login()
{
	var user = document.getElementById("user").value;
	var pwd = document.getElementById("pwd").value;
	if(user==""||user==null)
		alert("UserName is empty!!");
	else if(pwd==""||pwd==null)
		alert("PassWord is empty!!");
	else
		{
			if (window.XMLHttpRequest)
			  {// code for IE7+, Firefox, Chrome, Opera, Safari
			  xmlhttp=new XMLHttpRequest();
			  }
			else
			  {// code for IE6, IE5
			  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			  }
			if(xmlhttp!=null)
				{
					//md5加密
					pwd = hex_md5(pwd);
					var url = "../PHP/Login.php";
					url = url + "?user=" + user + "&pwd=" + pwd;
					url = url + "&sid=" + Math.random();
					xmlhttp.onreadystatechange=IsLogin;
					xmlhttp.open("GET",url,true);
					xmlhttp.send();
				}
		}
	
}

function IsLogin()
{
	if(xmlhttp.readyState==4)
		{
		//document.getElementById("isLogin").innerHTML=xmlhttp.responseText 
		if(xmlhttp.responseText=="1")
			{
			window.location.href='../HomePage.html';
			}
		else
			{
			alert("Wrong Message");
			}
		}
	
}

function Register()
{
	
}


function CreateXMLHttpRequest()
{
	var xmlhttp;
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	
}

function ClearUserText()
{
	var usertext = document.getElementById("user").value;
	if(usertext=="请输入账户名")
	{
		document.getElementById("user").value="";
		document.getElementById("user").focus();
	}
}

function ClearPasswordText()
{
	var usertext = document.getElementById("pwd").value;
	if(usertext=="请输入密码")
	{
		document.getElementById("pwd").value="";
		document.getElementById("pwd").focus();
	}
}

function KeyDown()
{
	if(event.keyCode==13)
	{
		Login();
		event.returnValue = false;
	}
}